﻿using System;
using FlashCards.SL.FlashCardCreator.DataService;
using FlashCards.Dto;
using System.Windows.Input;
using FlashCards.SL.FlashCardCreator.ViewModels.Commands;

namespace FlashCards.SL.FlashCardCreator.ViewModels
{
    public class FlashcardViewModel : BaseViewModel
    {
        private Flashcard _flashcard;

        public FlashcardViewModel(Flashcard flashcard)
        {
            _flashcard = flashcard;
            Term = new FlashcardPartViewModel(_flashcard.Term);
            Definition = new FlashcardPartViewModel(_flashcard.Definition);

            InitializeCommands();
        }

        public DateTime DateModified
        {
            get { return _flashcard.DateModified; }
        }

        private bool _isExpanded;
        public bool IsExpanded
        {
            get { return _isExpanded; }
            set { _isExpanded = value; OnPropertyChanged("IsExpanded"); }
        }

        public FlashcardPartViewModel Term { get; set; }
        public FlashcardPartViewModel Definition { get; set; }

        #region COMMANDS

        public ICommand RemoveFlashcardCommand { get; private set; }

        private void InitializeCommands()
        {
            RemoveFlashcardCommand = new Command(RemoveFlashcard);
        }

        void RemoveFlashcard()
        {
            FlashcardRemoving.Invoke(this, new FlashcardRemovingEventArgs(_flashcard));
        }

        public event EventHandler<FlashcardRemovingEventArgs> FlashcardRemoving;

        #endregion
    }

    public class FlashcardRemovingEventArgs : EventArgs
    {
        public Flashcard Flashcard { get; set; }

        public FlashcardRemovingEventArgs(Flashcard flashcard)
        {
            Flashcard = flashcard;
        }
    }
}
